import { customRequest } from "../request/custom";
import { get,post,put,del} from "../request/request";

// ///// 获取评论 /////
/**
 * 根据帖子Id获取其回复列表，:id为帖子的id
 * @param id 
 * @param callback 
 */
export const fetchReplyList = async (id:string,callback?: () => void | boolean) => {
  return customRequest(() => get(`/api/comment/${id}`), callback);
};
/**
 * 根据用户id获取评论列表
 * @param id 
 * @param callback 
 */
export const fetchUserReplyList = async (
  id: string,
  callback?: () => void | boolean
) => {
  return customRequest(() => get(`/api/comment/personal/${id}`), callback);
};


//  ///// 一级评论 /////

/**
 * 添加回复
 * @param id 帖子id
 * @param text 
 * @param callback 
 */
export const fetchAddReply = async (
  id: string,
  text: string,
  callback?: () => void | boolean
) => {
  return customRequest(
    () => post(`/api/comment/${id}`, { content: text }),
    callback
  );
};



// ///// 二级回复 /////
/**
 * 二级回复
 * @param id 
 * @param cid 
 * @param text 
 * @param callback 
 */
export const fetchAddToUserReply = async (
  id: string,
  cid: string,
  text: string,
  callback?: () => void | boolean
) => {
  return customRequest(
    () => post(`/api/discuss/${id}?rootCommentId=${cid}`, { content: text }),
    callback
  );
};

// ///// 三级回复 /////

/**
 * 三级回复
 * @param rpId 
 * @param text 
 * @param callback 
 */
export const fetchAddToUserReplyThird = async (
  rpId: string,
  text: string,
  callback?: () => void | boolean
) => {
  return customRequest(
    () => post(`/api/discuss/reply/${rpId}`, { content: text }),
    callback
  );
};

//    //////// 一级评论点赞 //////////////////
/**
 * 点赞一级评论
 * @param id 
 * @param callback 
 */
export const fetchAddLikingReply = async (
  id: string,
  callback?: () => void | boolean
) => {
  return customRequest(
    () => put(`/api/comment/likingReply/${id}`),
    callback
  );
};
/**
 * 取消点赞一级评论
 * @param id 
 * @param callback 
 */
export const fetchDelLikingReply = async (
  id: string,
  callback?: () => void | boolean
) => {
  return customRequest(() => del(`/api/comment/unlikingReply/${id}`), callback);
};

//    //////// 二三级评论点赞 //////////////////
/**
 * 点赞二三评论
 * @param id 
 * @param callback 
 */
export const fetchAddLikingDiscuss = async (
  id: string,
  callback?: () => void | boolean
) => {
  return customRequest(() => put(`/api/discuss/likingDiscuss/${id}`), callback);
};
/**
 * 取消点赞二三级评论
 * @param id 
 * @param callback 
 */
export const fetchDelLikingDiscuss = async (
  id: string,
  callback?: () => void | boolean
) => {
  return customRequest(
    () => del(`/api/discuss/unlikingDiscuss/${id}`),
    callback
  );
};